﻿using System;
using Codeflows;
using Codeflows.Dispatch;
using Codeflows.Results;

namespace CodeflowsTests.Scenarios
{
    public class DispatchCountingCodeflow : Codeflow
    {
        public Result Start(IActionContext context)
        {
            return context.DispatchAttemptsCount < 1 ? Retry() : Jump<DispatchCountingCodeflow>(c => c.Next(context.DispatchAttemptsCount, RuntimeValues.ActionContext));
        }

        public Result Next(int previousActionsDispatchAttemptsCount, IActionContext context)
        {
            if (context.DispatchAttemptsCount <= 2) 
                return Retry();

            return End(previousActionsDispatchAttemptsCount + context.DispatchAttemptsCount);
        }
    }
}
